/**
 * Copyright (c) 2016-2021 by the respective copyright holders.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package com.zsmartsystems.zigbee.dongle.xbee.internal.protocol;

import com.zsmartsystems.zigbee.ExtendedPanId;
import com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.CommandStatus;

/**
 * Class to implement the XBee command <b>Active Scan</b>.
 * <p>
 * AT Command <b>AS</b></p>Scans the neighborhood for beacon responses. The AS command is
 * only valid as a local command.
 * <p>
 * This class provides methods for processing XBee API commands.
 * <p>
 * Note that this code is autogenerated. Manual changes may be overwritten.
 *
 * @author Chris Jackson - Initial contribution of Java code generator
 */
public class XBeeActiveScanResponse extends XBeeFrame implements XBeeResponse {
    /**
     * Response field
     */
    private Integer frameId;

    /**
     * Response field
     */
    private CommandStatus commandStatus;

    /**
     * Response field
     */
    private Integer asType;

    /**
     * Response field
     */
    private Integer channel;

    /**
     * Response field
     */
    private ExtendedPanId extendedPanId;

    /**
     * Response field
     */
    private Boolean allowJoin;

    /**
     * Response field
     */
    private Integer stackProfile;

    /**
     * Response field
     */
    private Integer lqi;

    /**
     * Response field
     */
    private Integer rssi;

    /**
     *
     * @return the frameId as {@link Integer}
     */
    public Integer getFrameId() {
        return frameId;
    }

    /**
     *
     * @return the commandStatus as {@link CommandStatus}
     */
    public CommandStatus getCommandStatus() {
        return commandStatus;
    }

    /**
     *
     * @return the asType as {@link Integer}
     */
    public Integer getAsType() {
        return asType;
    }

    /**
     *
     * @return the channel as {@link Integer}
     */
    public Integer getChannel() {
        return channel;
    }

    /**
     *
     * @return the extendedPanId as {@link ExtendedPanId}
     */
    public ExtendedPanId getExtendedPanId() {
        return extendedPanId;
    }

    /**
     *
     * @return the allowJoin as {@link Boolean}
     */
    public Boolean getAllowJoin() {
        return allowJoin;
    }

    /**
     *
     * @return the stackProfile as {@link Integer}
     */
    public Integer getStackProfile() {
        return stackProfile;
    }

    /**
     *
     * @return the lqi as {@link Integer}
     */
    public Integer getLqi() {
        return lqi;
    }

    /**
     *
     * @return the rssi as {@link Integer}
     */
    public Integer getRssi() {
        return rssi;
    }


    @Override
    public void deserialize(int[] incomingData) {
        initialiseDeserializer(incomingData);

        // Deserialize the fields for the response

        // Deserialize field "Frame ID"
        frameId = deserializeInt8();
        deserializeAtCommand();

        // Deserialize field "Command Status"
        commandStatus = deserializeCommandStatus();
        if (commandStatus != CommandStatus.OK || isComplete()) {
            return;
        }

        // Deserialize field "AS_type"
        asType = deserializeInt8();

        // Deserialize field "Channel"
        channel = deserializeInt8();

        // Deserialize field "Extended PAN ID"
        extendedPanId = deserializeExtendedPanId();

        // Deserialize field "Allow Join"
        allowJoin = deserializeBoolean();

        // Deserialize field "Stack Profile"
        stackProfile = deserializeInt8();

        // Deserialize field "LQI"
        lqi = deserializeInt8();

        // Deserialize field "RSSI"
        rssi = deserializeInt8();
    }

    @Override
    public String toString() {
        final StringBuilder builder = new StringBuilder(1012);
        builder.append("XBeeActiveScanResponse [frameId=");
        builder.append(frameId);
        builder.append(", commandStatus=");
        builder.append(commandStatus);
        if (commandStatus == CommandStatus.OK) {
            builder.append(", asType=");
            builder.append(asType);
            builder.append(", channel=");
            builder.append(channel);
            builder.append(", extendedPanId=");
            builder.append(extendedPanId);
            builder.append(", allowJoin=");
            builder.append(allowJoin);
            builder.append(", stackProfile=");
            builder.append(stackProfile);
            builder.append(", lqi=");
            builder.append(lqi);
            builder.append(", rssi=");
            builder.append(rssi);
        }
        builder.append(']');
        return builder.toString();
    }
}
